<template>
  <div class="analysis">
    <!--<div class="info-back">-->
              <!--<div class="back-icon" @click="back()">-->
                  <!--<i class="fa fa-arrow-left" aria-hidden="true"></i>-->
              <!--</div>-->
    <!--</div>-->
    <el-tabs v-model="activeName" @tab-click="handleClick" style="padding-top: 10px">
      <el-tab-pane label="日报表" name="day">
        <v-reportitem :activeName="activeName" :tableData="tableData"
          ></v-reportitem>
      </el-tab-pane>
      <el-tab-pane label="月报表" name="month">
        <v-reportitem :activeName="activeName" :tableData="tableData"
          ></v-reportitem>
      </el-tab-pane>
    </el-tabs>
  </div>

</template>

<script>
  import moment from 'moment';
  import vReportitem from './ReportItem.vue';
  export default {
    name:'keepAilve',
      data: function () {

          return {
             activeName: 'day',
             tableData: [],
             loading: false

          }
      },
      components:{
          vReportitem
      },
      created: function (){
          this.$$("#content").scrollTop(0)
        console.log("created");
        this.read();
      },
      methods: {
        handleClick(tab, event) {
          console.log(tab, event);
          console.log(tab.name)

          console.log(this.activeName);
          this.read();
        },
        read:function () {
          console.log("read")
          let self = this;
          let url = '';
          if(this.activeName == "month"){
            let currentDate = new Date();
            let bizDate = moment(currentDate).format('YYYY-MM-DD');
            url = '/commission/month?bizDate='+ bizDate;
          }else if (this.activeName == "day") {
            url = '/commission/';
          }

          self.loading = true;

          this.$axioxs({
               method: 'get',
               url: url
            })
          .then(function (res) {
              console.log(JSON.stringify(res.data));
              console.log(res.data);
              self.loading = false;
              self.tableData = res.data.records;
              if(self.activeName == "month"){
                for(var i=0; i<self.tableData.length; i++){
                  console.log(self.tableData[i]);
                  self.tableData[i].bizDate = moment(self.tableData[i].bizDate).format("YYYY-MM");
                }

              }
          })
          .catch(function (error) {
            console.log(error);
            self.loading = true;
          });
        },

        back: function () {
          this.$router.push({
            path:'/analysis',
          });
        }

      }

  }
</script>

<style scoped>

</style>
